function dedup(list) {
    return [...new Set(list)]
}

function is_nice_image(img) {
    return img.currentSrc && (img.currentSrc.startsWith('http://') || img.currentSrc.startsWith('https://'))
}

function parse_images(doc) {
    const image_nodes = [...doc.getElementsByTagName('img')]
    return image_nodes.filter(
        is_nice_image
    ).map(img => {
        let u = new URL(img.currentSrc)
        u.hash = u.search = ''
        return u.toString().trim()
    })
}

chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
    // 处理来自popup页面的请求
    images = parse_images(document)
    sendResponse(dedup(images));
});
